package com.mybatis;

import com.mybatis.bz.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException {
        System.out.println( "Hello World!" );
        //获取资源文件的路径
        String resource = "mybatis-config.xml";

        //加载资源文件
        InputStream inputStream = Resources.getResourceAsStream(resource);
        //提取sql会话工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //打开会话工厂
        SqlSession session = sqlSessionFactory.openSession();
        try {
            //
            User user = (User) session.selectOne("com.mybatis.bz.dao.UserDao.queryUserById", 8);
            System.out.println(user );
        } finally {
            session.close();
        }
    }
}
